home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-13 | 34.8 KB | 1,357 lines |
- head 5.4;
- branch ;
- access ;
- symbols beta4:5.0;
- locks ; strict;
- comment @ * @;
-
-
- 5.4
- date 88.10.01.10.39.05; author ouster; state Exp;
- branches ;
- next 5.3;
-
- 5.3
- date 88.09.15.16.47.44; author ouster; state Exp;
- branches ;
- next 5.2;
-
- 5.2
- date 88.09.15.16.31.16; author ouster; state Exp;
- branches ;
- next 5.1;
-
- 5.1
- date 88.03.27.21.17.17; author deboor; state Exp;
- branches ;
- next 5.0;
-
- 5.0
- date 87.09.11.11.26.12; author deboor; state Exp;
- branches ;
- next 1.5;
-
- 1.5
- date 87.08.21.20.35.02; author deboor; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 87.06.20.19.56.46; author deboor; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 87.06.17.17.18.20; author deboor; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 87.06.17.16.16.21; author deboor; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 87.06.16.12.21.13; author deboor; state Exp;
- branches ;
- next ;
-
-
- desc
- @keyboard interface
- @
-
-
- 5.4
- log
- @Back-fit Adam's fixes to autorepeat (they got made after I copied
- this file).
- @
- text
- @/*-
- * spriteKbd.c --
- * Functions for retrieving data from a keyboard.
- *
- * Copyright (c) 1987 by the Regents of the University of California
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- *
- *
- */
- #ifndef lint
- static char rcsid[] =
- "$Header: spriteKbd.c,v 5.3 88/09/15 16:47:44 ouster Exp $ SPRITE (Berkeley)";
- #endif lint
-
- #define Time SpriteTime
- #include <fs.h>
- #undef Time
-
- #define NEED_EVENTS
- #include "spriteddx.h"
-
- #include <bit.h>
-
- #include <errno.h>
- #include <fcntl.h>
- #include <sys/file.h>
- #include <sys/time.h>
-
- #include "keysym.h"
-
- #define VKEY_UP 0x80
- #define VKEY_REPEAT 0x40
- #define VKEY_DOWN 0
-
- #define MIN_KEYCODE 8 /* Keycode below which we may not transmit */
-
- /*
- * These constants are for Sun 2 and 3 keyboards only
- */
- #define KBD_RESET '\1'
- #define KBD_BELL_ON '\2'
- #define KBD_BELL_OFF '\3'
- #define KBD_CLICK_ON '\12'
- #define KBD_CLICK_OFF '\13'
-
- static void spriteBell();
- static void spriteKbdCtrl();
- static Dev_KbdEvent *spriteKbdGetEvents();
- static void spriteKbdProcessEvent();
- static void spriteKbdDoneEvents();
-
- /*
- * Auto-repeat stuff.
- */
- static enum {
- REPEAT_LONG, /* Start repeat with long timeout */
- REPEAT_SHORT, /* Start repeat with short timeout */
- REPEAT_TIMEOUT, /* In the middle of a timeout */
- REPEAT_PENDING, /* Repeat should be taken next */
- REPEAT_NONE /* No repeat should happen */
- } repeatPhase = REPEAT_NONE;
-
- static Dev_KbdEvent repeatEvent; /* Event that will be repeated */
- static SpriteTime repeatTimeout; /* Timeout to use for repeating */
- static unsigned int repeatDelta; /* Timeout length (ms) */
- #define REPEAT_LONG_TIMEOUT 500 /* Ms delay to begin repeat */
- #define REPEAT_SHORT_TIMEOUT 10 /* Ms delay to continue repeat */
-
- static KbPrivRec sysKbPriv = {
- -1, /* Type of keyboard */
- -1, /* Descriptor open to device */
- spriteKbdGetEvents, /* Function to read events */
- spriteKbdProcessEvent, /* Function to process an event */
- spriteKbdDoneEvents, /* Function called when all events */
- /* have been handled. */
- 0, /* Keycode offset */
- &defaultKeyboardControl, /* Current keyboard control */
- (pointer)NULL, /* Private to keyboard (nothing needed) */
- };
-
-
- /*
- * XXX - Its not clear what to map these to for now.
- * keysyms.h doesn't define enough function key names.
- */
-
- #ifndef XK_L1
- #define XK_L1 XK_Cancel
- #define XK_L2 XK_Redo
- #define XK_L3 XK_Menu
- #define XK_L4 XK_Undo
- #define XK_L5 XK_Insert
- #define XK_L6 XK_Select
- #define XK_L7 XK_Execute
- #define XK_L8 XK_Print
- #define XK_L9 XK_Find
- #define XK_L10 XK_Help
- #define XK_R1 NoSymbol
- #define XK_R2 NoSymbol
- #define XK_R3 NoSymbol
- #define XK_R4 NoSymbol
- #define XK_R5 NoSymbol
- #define XK_R6 NoSymbol
- #define XK_R7 NoSymbol
- #define XK_R8 XK_Up
- #define XK_R9 NoSymbol
- #define XK_R10 XK_Left
- #define XK_R11 XK_Home
- #define XK_R12 XK_Right
- #define XK_R13 NoSymbol
- #define XK_R14 XK_Down
- #define XK_R15 NoSymbol
- #endif
-
- static KeySym sunKbdMap[] = {
- XK_L1, NoSymbol, /* 0x01 */
- NoSymbol, NoSymbol, /* 0x02 */
- XK_L2, NoSymbol, /* 0x03 */
- NoSymbol, NoSymbol, /* 0x04 */
- XK_F1, NoSymbol, /* 0x05 */
- XK_F2, NoSymbol, /* 0x06 */
- NoSymbol, NoSymbol, /* 0x07 */
- XK_F3, NoSymbol, /* 0x08 */
- NoSymbol, NoSymbol, /* 0x09 */
- XK_F4, NoSymbol, /* 0x0a */
- NoSymbol, NoSymbol, /* 0x0b */
- XK_F5, NoSymbol, /* 0x0c */
- NoSymbol, NoSymbol, /* 0x0d */
- XK_F6, NoSymbol, /* 0x0e */
- NoSymbol, NoSymbol, /* 0x0f */
- XK_F7, NoSymbol, /* 0x10 */
- XK_F8, NoSymbol, /* 0x11 */
- XK_F9, NoSymbol, /* 0x12 */
- XK_Break, NoSymbol, /* 0x13 */
- NoSymbol, NoSymbol, /* 0x14 */
- XK_R1, NoSymbol, /* 0x15 */
- XK_R2, NoSymbol, /* 0x16 */
- XK_R3, NoSymbol, /* 0x17 */
- NoSymbol, NoSymbol, /* 0x18 */
- XK_L3, NoSymbol, /* 0x19 */
- XK_L4, NoSymbol, /* 0x1a */
- NoSymbol, NoSymbol, /* 0x1b */
- NoSymbol, NoSymbol, /* 0x1c */
- XK_Escape, NoSymbol, /* 0x1d */
- XK_1, XK_exclam, /* 0x1e */
- XK_2, XK_at, /* 0x1f */
- XK_3, XK_numbersign, /* 0x20 */
- XK_4, XK_dollar, /* 0x21 */
- XK_5, XK_percent, /* 0x22 */
- XK_6, XK_asciicircum, /* 0x23 */
- XK_7, XK_ampersand, /* 0x24 */
- XK_8, XK_asterisk, /* 0x25 */
- XK_9, XK_parenleft, /* 0x26 */
- XK_0, XK_parenright, /* 0x27 */
- XK_minus, XK_underscore, /* 0x28 */
- XK_equal, XK_plus, /* 0x29 */
- XK_quoteleft, XK_asciitilde, /* 0x2a */
- XK_BackSpace, NoSymbol, /* 0x2b */
- NoSymbol, NoSymbol, /* 0x2c */
- XK_R4, NoSymbol, /* 0x2d */
- XK_R5, NoSymbol, /* 0x2e */
- XK_R6, NoSymbol, /* 0x2f */
- NoSymbol, NoSymbol, /* 0x30 */
- XK_L5, NoSymbol, /* 0x31 */
- NoSymbol, NoSymbol, /* 0x32 */
- XK_L6, NoSymbol, /* 0x33 */
- NoSymbol, NoSymbol, /* 0x34 */
- XK_Tab, NoSymbol, /* 0x35 */
- XK_Q, NoSymbol, /* 0x36 */
- XK_W, NoSymbol, /* 0x37 */
- XK_E, NoSymbol, /* 0x38 */
- XK_R, NoSymbol, /* 0x39 */
- XK_T, NoSymbol, /* 0x3a */
- XK_Y, NoSymbol, /* 0x3b */
- XK_U, NoSymbol, /* 0x3c */
- XK_I, NoSymbol, /* 0x3d */
- XK_O, NoSymbol, /* 0x3e */
- XK_P, NoSymbol, /* 0x3f */
- XK_bracketleft, XK_braceleft, /* 0x40 */
- XK_bracketright, XK_braceright, /* 0x41 */
- XK_Delete, NoSymbol, /* 0x42 */
- NoSymbol, NoSymbol, /* 0x43 */
- XK_R7, NoSymbol, /* 0x44 */
- XK_Up, XK_R8, /* 0x45 */
- XK_R9, NoSymbol, /* 0x46 */
- NoSymbol, NoSymbol, /* 0x47 */
- XK_L7, NoSymbol, /* 0x48 */
- XK_L8, NoSymbol, /* 0x49 */
- NoSymbol, NoSymbol, /* 0x4a */
- NoSymbol, NoSymbol, /* 0x4b */
- XK_Control_L, NoSymbol, /* 0x4c */
- XK_A, NoSymbol, /* 0x4d */
- XK_S, NoSymbol, /* 0x4e */
- XK_D, NoSymbol, /* 0x4f */
- XK_F, NoSymbol, /* 0x50 */
- XK_G, NoSymbol, /* 0x51 */
- XK_H, NoSymbol, /* 0x52 */
- XK_J, NoSymbol, /* 0x53 */
- XK_K, NoSymbol, /* 0x54 */
- XK_L, NoSymbol, /* 0x55 */
- XK_semicolon, XK_colon, /* 0x56 */
- XK_quoteright, XK_quotedbl, /* 0x57 */
- XK_backslash, XK_bar, /* 0x58 */
- XK_Return, NoSymbol, /* 0x59 */
- NoSymbol, NoSymbol, /* 0x5a */
- XK_Left, XK_R10, /* 0x5b */
- XK_R11, NoSymbol, /* 0x5c */
- XK_Right, NoSymbol, /* 0x5d */
- NoSymbol, NoSymbol, /* 0x5e */
- XK_L9, NoSymbol, /* 0x5f */
- NoSymbol, NoSymbol, /* 0x60 */
- XK_L10, NoSymbol, /* 0x61 */
- NoSymbol, NoSymbol, /* 0x62 */
- XK_Shift_L, NoSymbol, /* 0x63 */
- XK_Z, NoSymbol, /* 0x64 */
- XK_X, NoSymbol, /* 0x65 */
- XK_C, NoSymbol, /* 0x66 */
- XK_V, NoSymbol, /* 0x67 */
- XK_B, NoSymbol, /* 0x68 */
- XK_N, NoSymbol, /* 0x69 */
- XK_M, NoSymbol, /* 0x6a */
- XK_comma, XK_less, /* 0x6b */
- XK_period, XK_greater, /* 0x6c */
- XK_slash, XK_question, /* 0x6d */
- XK_Shift_R, NoSymbol, /* 0x6e */
- XK_Linefeed, NoSymbol, /* 0x6f */
- XK_R13, NoSymbol, /* 0x70 */
- XK_Down, XK_R14, /* 0x71 */
- XK_R15, NoSymbol, /* 0x72 */
- NoSymbol, NoSymbol, /* 0x73 */
- NoSymbol, NoSymbol, /* 0x74 */
- NoSymbol, NoSymbol, /* 0x75 */
- NoSymbol, NoSymbol, /* 0x76 */
- XK_Caps_Lock, NoSymbol, /* 0x77 */
- XK_Meta_L, NoSymbol, /* 0x78 */
- XK_space, NoSymbol, /* 0x79 */
- XK_Meta_R, NoSymbol, /* 0x7a */
- NoSymbol, NoSymbol, /* 0x7b */
- NoSymbol, NoSymbol, /* 0x7c */
- NoSymbol, NoSymbol, /* 0x7d */
- NoSymbol, NoSymbol, /* 0x7e */
- NoSymbol, NoSymbol, /* 0x7f */
- };
-
- static KeySymsRec sunMapDesc = {
- /* map minKeyCode maxKeyCode width */
- sunKbdMap, 1, 0x7a, 2
- };
-
- #define cT (ControlMask)
- #define sH (ShiftMask)
- #define lK (LockMask)
- #define mT (Mod1Mask)
- static CARD8 sunModMap[MAP_LENGTH] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00-0f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10-1f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20-2f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 30-3f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40-4f */
- 0, 0, 0, cT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50-5f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sH, 0, 0, 0, 0, 0, /* 60-6f */
- 0, 0, 0, 0, 0, sH, 0, 0, 0, 0, 0, 0, 0, 0, lK, mT,/* 70-7f */
- 0, mT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80-8f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90-9f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a0-af */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b0-bf */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c0-cf */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d0-df */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e0-ef */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f0-ff */
- };
-
-
- /*-
- *-----------------------------------------------------------------------
- * spriteKbdProc --
- * Handle the initialization, etc. of a keyboard.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * None.
- *
- *-----------------------------------------------------------------------
- */
- /*ARGSUSED*/
- int
- spriteKbdProc (pKeyboard, what, argc, argv)
- DevicePtr pKeyboard; /* Keyboard to manipulate */
- int what; /* What to do to it */
- int argc;
- char **argv;
- {
- register int fd;
- int tmp;
- KbPrivPtr pPriv;
- int i;
- char reset = KBD_RESET;
- BYTE map[MAP_LENGTH];
-
- switch (what) {
- case DEVICE_INIT:
- if (pKeyboard != LookupKeyboardDevice()) {
- ErrorF ("Cannot open non-system keyboard");
- return (!Success);
- }
- /*
- * First open and find the current state of the keyboard
- * If we are reinitializing, then turn the device OFF first.
- */
- if (sysKbPriv.fd >= 0) {
- fd = sysKbPriv.fd;
- } else {
- ReturnStatus status;
-
- status = Fs_Open("/dev/Xevent",
- FS_NON_BLOCKING|FS_READ|FS_WRITE, 0, &sysKbPriv.fd);
- if (status != 0) {
- errno = Compat_MapCode(status);
- Error ("Opening /dev/Xevent");
- return (!Success);
- }
- fd = sysKbPriv.fd;
- }
-
- /*
- * Perform final initialization of the system private keyboard
- * structure and fill in various slots in the device record
- * itself which couldn't be filled in before.
- */
- pKeyboard->devicePrivate = (pointer)&sysKbPriv;
-
- pKeyboard->on = FALSE;
- /*
- * Make sure keycodes we send out are >= MIN_KEYCODE
- */
- if (sunMapDesc.minKeyCode < MIN_KEYCODE) {
- int offset;
-
- offset = MIN_KEYCODE - sunMapDesc.minKeyCode;
- sunMapDesc.minKeyCode += offset;
- sunMapDesc.maxKeyCode += offset;
- sysKbPriv.offset = offset;
- }
-
- InitKeyboardDeviceStruct(pKeyboard, &sunMapDesc, sunModMap,
- spriteBell, spriteKbdCtrl);
-
- /*
- * Reset keyboard to avoid spurious events (No! don't do now:
- * doesn't work in Sprite).
- (void) write(fd, &reset, 1);
- */
- break;
- case DEVICE_ON:
- pKeyboard->on = TRUE;
- AddEnabledDevice(((KbPrivPtr)pKeyboard->devicePrivate)->fd);
- /*
- * Initialize auto-repeat.
- */
- repeatPhase = REPEAT_NONE;
- break;
- case DEVICE_CLOSE:
- case DEVICE_OFF:
- pKeyboard->on = FALSE;
- RemoveEnabledDevice(((KbPrivPtr)pKeyboard->devicePrivate)->fd);
- /*
- * Make sure auto-repeat doesn't generate events now that the
- * keyboard is off.
- */
- repeatPhase = REPEAT_NONE;
- break;
- }
- return (Success);
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteBell --
- * Ring the terminal/keyboard bell
- *
- * Results:
- * None.
- *
- * Side Effects:
- * None, really...
- *
- *-----------------------------------------------------------------------
- */
- static void
- spriteBell (loudness, pKeyboard)
- int loudness; /* Percentage of full volume */
- DevicePtr pKeyboard; /* Keyboard to ring */
- {
- KbPrivPtr pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
- char kbdCmd;
- struct timeval sleepTime;
-
- if (loudness == 0) {
- return;
- }
-
- kbdCmd = KBD_BELL_ON;
- (void) write(pPriv->fd, &kbdCmd, 1);
-
- sleepTime.tv_usec = pPriv->ctrl->bell_duration * 1000;
- sleepTime.tv_sec = 0;
- while (sleepTime.tv_usec >= 1000000) {
- sleepTime.tv_sec += 1;
- sleepTime.tv_usec -= 1000000;
- }
- (void) select(0, (int *) 0, (int *) 0, (int *) 0, &sleepTime);
-
- kbdCmd = KBD_BELL_OFF;
- (void) write(pPriv->fd, &kbdCmd, 1);
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteKbdCtrl --
- * Alter some of the keyboard control parameters
- *
- * Results:
- * None.
- *
- * Side Effects:
- * Some...
- *
- *-----------------------------------------------------------------------
- */
- static void
- spriteKbdCtrl (pKeyboard, ctrl)
- DevicePtr pKeyboard; /* Keyboard to alter */
- KeybdCtrl *ctrl; /* New control info */
- {
- KbPrivPtr pPriv;
- char kbCmd;
-
- pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
-
- pPriv->ctrl = ctrl;
- if (ctrl->click) {
- kbCmd = KBD_CLICK_ON;
- } else {
- kbCmd = KBD_CLICK_OFF;
- }
-
- (void) write(pPriv->fd, &kbCmd, 1);
-
- if (!ctrl->autoRepeat) {
- repeatPhase = REPEAT_NONE;
- }
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteKbdGetEvents --
- * Return the events waiting in the wings for the given keyboard.
- *
- * Results:
- * A pointer to an array of Firm_events or (Firm_event *)0 if no events
- * The number of events contained in the array.
- *
- * Side Effects:
- * None.
- *-----------------------------------------------------------------------
- */
- static Dev_KbdEvent *
- spriteKbdGetEvents (pKeyboard, pNumEvents)
- DevicePtr pKeyboard; /* Keyboard to read */
- int *pNumEvents; /* Place to return number of events */
- {
- static Dev_KbdEvent evBuf[MAXEVENTS]; /* Buffer for input events */
-
- if (repeatPhase == REPEAT_PENDING) {
- /*
- * This will only have been set if no streams were really ready, thus
- * there are no events to read from Xevent.
- */
- repeatEvent.keyUp = VKEY_REPEAT;
- repeatEvent.time += repeatDelta / 2;
- evBuf[0] = repeatEvent;
-
- repeatEvent.keyUp = VKEY_DOWN;
- repeatEvent.time += repeatDelta / 2;
- evBuf[1] = repeatEvent;
-
- *pNumEvents = 2;
-
- repeatPhase = REPEAT_SHORT;
- } else {
- int nBytes; /* number of bytes of events available. */
- KbPrivPtr pPriv;
- int i;
-
- pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
- nBytes = read(pPriv->fd, (char *) evBuf, sizeof(evBuf));
- if (nBytes >= 0) {
- *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
- } else if (errno == EWOULDBLOCK) {
- *pNumEvents = 0;
- } else {
- FatalError ("Could not read the keyboard");
- }
- }
- return (evBuf);
- }
-
-
- /*-
- *-----------------------------------------------------------------------
- * spriteKbdProcessEvent --
- * Transform a Sprite event into an X one.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * An event is passed to DIX. The last VKEY_DOWN event is stored in
- * repeatEvent and repeatPhase set to REPEAT_INITIAL if we're doing
- * autorepeat and the key is to be repeated.
- *
- *-----------------------------------------------------------------------
- */
- static void
- spriteKbdProcessEvent (pKeyboard, ev)
- DevicePtr pKeyboard;
- Dev_KbdEvent *ev;
- {
- xEvent xE;
- register KbPrivPtr pPriv;
- register int smask;
- PtrPrivPtr ptrPriv;
-
- pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
- ptrPriv = (PtrPrivPtr) LookupPointerDevice()->devicePrivate;
-
- xE.u.keyButtonPointer.time = ev->time;
- xE.u.keyButtonPointer.rootX = ptrPriv->x;
- xE.u.keyButtonPointer.rootY = ptrPriv->y;
- xE.u.u.detail = ev->key + pPriv->offset;
- if (ev->keyUp) {
- xE.u.u.type = KeyRelease;
- if ((ev->keyUp == VKEY_UP) &&
- (repeatPhase != REPEAT_NONE) &&
- (repeatEvent.key == ev->key)) {
- /*
- * Turn off repeat if we got a real up event for the key
- * being repeated
- */
- repeatPhase = REPEAT_NONE;
- }
- } else {
- xE.u.u.type = KeyPress;
- if ((repeatPhase != REPEAT_SHORT) &&
- (pPriv->ctrl->autoRepeat ||
- Bit_IsSet (xE.u.u.detail, pPriv->ctrl->autoRepeats))) {
- repeatEvent = *ev;
- repeatPhase = REPEAT_LONG;
- }
- }
-
- (* pKeyboard->processInputProc) (&xE, pKeyboard);
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteDoneEvents --
- * Nothing to do, here...
- *
- * Results:
- *
- * Side Effects:
- *
- *-----------------------------------------------------------------------
- */
- static void
- spriteKbdDoneEvents (pKeyboard, final)
- DevicePtr pKeyboard;
- Bool final;
- {
- }
-
- /*-
- *-----------------------------------------------------------------------
- * LegalModifier --
- * See if a key is legal as a modifier. We're very lenient around,
- * here, so we always return true.
- *
- * Results:
- * TRUE.
- *
- * Side Effects:
- * None.
- *
- *-----------------------------------------------------------------------
- */
- Bool
- LegalModifier (key)
- int key;
- {
- return (TRUE);
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteBlockHandler --
- * Tell the OS layer when to timeout to implement auto-repeat.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * The timeout value may be overwritten.
- *
- *-----------------------------------------------------------------------
- */
- void
- spriteBlockHandler (index, pKeyboard, ppTime, pReadMask)
- int index; /* Screen index */
- DevicePtr pKeyboard; /* Keyboard for which to do auto-repeat */
- SpriteTime **ppTime; /* Pointer to timeout to use */
- int *pReadMask; /* Mask the OS Layer will use for select. */
- {
- if (repeatPhase == REPEAT_LONG) {
- /*
- * Beginning long timeout
- */
- repeatDelta = REPEAT_LONG_TIMEOUT;
- } else if (repeatPhase == REPEAT_SHORT) {
- /*
- * Beginning short timeout
- */
- repeatDelta = REPEAT_SHORT_TIMEOUT;
- } else if (repeatPhase == REPEAT_NONE) {
- /*
- * No repeat necessary -- it can block as long as it wants to
- */
- return;
- } else if (repeatPhase == REPEAT_TIMEOUT) {
- /*
- * Interrupted timeout -- use old timeout (that was modified by
- * select in the OS layer)
- */
- *ppTime = &repeatTimeout;
- return;
- }
- repeatTimeout.seconds = repeatDelta / 1000;
- repeatTimeout.microseconds = repeatDelta * 1000;
- repeatPhase = REPEAT_TIMEOUT;
- *ppTime = &repeatTimeout;
- }
-
- /*-
- *-----------------------------------------------------------------------
- * spriteWakeupHandler --
- * Figure out if should do a repeat when the server wakes up. Because
- * select will modify repeatTimeout to contain the time left, we
- * can tell if the thing timed out.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * repeatPhase may be changed to REPEAT_PENDING. If it is, *pNumReady
- * will be set to 1 and the keyboard's stream marked ready in the
- * result mask.
- *
- *-----------------------------------------------------------------------
- */
- void
- spriteWakeupHandler (index, pKeyboard, pNumReady, pReadMask)
- int index; /* Screen index */
- DevicePtr pKeyboard; /* Keyboard to repeat */
- int *pNumReady; /* Pointer to number of ready streams */
- int *pReadMask; /* Ready streams */
- {
- KbPrivPtr pPriv;
-
- pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
-
- if ((repeatPhase == REPEAT_TIMEOUT) && (*pNumReady == 0)) {
- repeatPhase = REPEAT_PENDING;
- Bit_Set (pPriv->fd, pReadMask);
- *pNumReady = 1;
- }
- }
- @
-
-
- 5.3
- log
- @Latest changs from Adam for auto-repeat.
- @
- text
- @d19 1
- a19 1
- "$Header: spriteKbd.c,v 5.2 88/09/15 16:31:16 ouster Exp $ SPRITE (Berkeley)";
- d358 3
- a360 1
- * Reset keyboard to avoid spurious events
- a361 1
- (void) write(fd, &reset, 1);
- d375 5
- @
-
-
- 5.2
- log
- @Changes to get running under new C library.
- @
- text
- @d19 1
- a19 1
- "$Header: spriteKbd.c,v 5.1 88/03/27 21:17:17 deboor Exp $ SPRITE (Berkeley)";
- d68 1
- a68 1
- } repeatPhase;
- d303 1
- d365 4
- @
-
-
- 5.1
- log
- @*** empty log message ***
- @
- text
- @d19 1
- a19 1
- "$Header: spriteKbd.c,v 5.0 87/09/11 11:26:12 deboor Exp $ SPRITE (Berkeley)";
- d22 4
- a28 2
- #define Time SpriteTime
- #include <fs.h>
- a29 1
- #undef Time
- d31 5
- d44 9
- a302 1
- int tmp;
- d305 1
- d321 8
- a328 4
- if (Fs_Open("/dev/Xevent", FS_READ|FS_WRITE|FS_NON_BLOCKING, 0,
- &sysKbPriv.fd) != SUCCESS) {
- Error ("Opening /dev/Xevent");
- return (!Success);
- d355 5
- d392 3
- a394 4
- KbPrivPtr pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
- char kbdCmd;
- int junk;
- SpriteTime sleepTime;
- d400 8
- a407 8
- kbdCmd = '\2';
- (void)Fs_Write(pPriv->fd, 1, &kbdCmd, &junk);
-
- sleepTime.microseconds = pPriv->ctrl->bell_duration * 1000;
- sleepTime.seconds = 0;
- while (sleepTime.microseconds >= 1000000) {
- sleepTime.seconds += 1;
- sleepTime.microseconds -= 1000000;
- d409 1
- a409 1
- (void)Sync_WaitTime(sleepTime);
- d411 2
- a412 2
- kbdCmd = '\3';
- (void)Fs_Write(pPriv->fd, 1, &kbdCmd, &junk);
- d434 1
- a434 3
- int junk;
- static char KBD_CLICK_ON = '\12';
- static char KBD_CLICK_OFF = '\13';
- d440 1
- a440 1
- (void)Fs_Write(pPriv->fd, 1, &KBD_CLICK_ON, &junk);
- d442 1
- a442 1
- (void)Fs_Write(pPriv->fd, 1, &KBD_CLICK_OFF, &junk);
- d445 2
- d494 7
- a500 9
- switch (Fs_Read (pPriv->fd, sizeof(evBuf), evBuf, &nBytes)) {
- case SUCCESS:
- *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
- break;
- case FS_WOULD_BLOCK:
- *pNumEvents = 0;
- break;
- default:
- FatalError ("Could not read the keyboard");
- d640 1
- a640 1
- * Fs_Select in the OS layer)
- d655 1
- a655 1
- * Fs_Select will modify repeatTimeout to contain the time left, we
- @
-
-
- 5.0
- log
- @beta 4 release
- @
- text
- @a15 2
- * TODO:
- * Nuke strings on the various function keys (arrow/alternate)
- d19 1
- a19 1
- "$Header: spriteKbd.c,v 1.5 87/08/21 20:35:02 deboor Exp $ SPRITE (Berkeley)";
- d24 1
- d27 1
- d32 3
- a34 2
- #define VKEY_UP 0x80
- #define VKEY_DOWN 0
- d36 2
- d44 10
- d55 6
- d68 2
- d79 1
- a79 1
-
- d82 8
- a92 2
- #define XK_L3 XK_Menu
- #define XK_L4 XK_Undo
- a95 2
- #define XK_L5 XK_Insert
- #define XK_L6 XK_Select
- a98 2
- #define XK_L7 XK_Execute
- #define XK_L8 XK_Print
- a101 2
- #define XK_L9 XK_Find
- #define XK_L10 XK_Help
- d105 1
- a106 1
-
- a236 5
- static ModifierMapRec sunModMap = {
- /* lock shfta shftb ctrla ctrlb m1a m1b m2a m2b m3a m3b m4a m4b m5a m5b */
- 0x77, 0x63, 0x6e, 0x4c, 0, 0x78, 0x7a, 0, 0, 0, 0, 0, 0, 0, 0,
- };
-
- d242 24
- d275 1
- a276 1
- * Need to nuke strings for arrow keys! (and Alternate key?)
- d279 1
- d281 1
- a281 1
- spriteKbdProc (pKeyboard, what)
- d284 2
- d306 1
- a306 1
- if (Fs_Open ("/dev/Xevent", FS_READ | FS_NON_BLOCKING, 0,
- d322 13
- a334 1
- InitKeyboardDeviceStruct(pKeyboard, &sunMapDesc, &sunModMap,
- d368 22
- a389 1
- /* no can do, for now */
- d406 1
- a406 1
- spriteKbdCtrl (pKeyboard)
- d408 1
- d410 17
- a426 1
- /* can only change key click on sprite 3 keyboards, so what's the use? */
- d447 1
- a447 3
- int nBytes; /* number of bytes of events available. */
- KbPrivPtr pPriv;
- static Dev_KbdEvent evBuf[MAXEVENTS]; /* Buffer for Firm_events */
- d449 32
- a480 10
- pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
- switch (Fs_Read (pPriv->fd, sizeof(evBuf), evBuf, &nBytes)) {
- case SUCCESS:
- *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
- break;
- case FS_WOULD_BLOCK:
- *pNumEvents = 0;
- break;
- default:
- FatalError ("Could not read the keyboard");
- d489 1
- d492 1
- d495 3
- a498 13
- * Sometimes extra events will be passed to ProcessInput b/c the
- * state of the keyboard modifier keys is different for certain
- * keys on a sprite than on a microvax. e.g. typing '<' will cause
- * a KEY_SHIFT to be sent to dix earlier, but on a microvax, it should
- * only generate a KEY_LANGLE_RANGLE code, so an up event on KEY_SHIFT,
- * a down event on KEY_LANGLE_RANGLE and a down event on KEY_SHIFT
- * will be generated. Well, at least it's a standard...
- * A nicer approach would be to play with the KeyButtonMask variable
- * in dix, but that is forbidden...
- *
- * Note:
- * Since alpha1, DDXEventRec has gone away and we now directly translate
- * into Xevent. Therefore, much of this code was rewritten.
- d517 21
- a537 2
- xE.u.u.type = (ev->keyUp ? KeyRelease : KeyPress);
- xE.u.u.detail = ev->key;
- d579 84
- @
-
-
- 1.5
- log
- @Nuked the sun-originated keysyms for the weird function keys (left and right)
- @
- text
- @d21 1
- a21 1
- "$Header: spriteKbd.c,v 1.4 87/06/20 19:56:46 deboor Exp $ SPRITE (Berkeley)";
- d59 2
- a60 2
- #define XK_L1 NoSymbol
- #define XK_L2 NoSymbol
- d64 2
- a65 2
- #define XK_L3 NoSymbol
- #define XK_L4 NoSymbol
- d69 2
- a70 2
- #define XK_L5 NoSymbol
- #define XK_L6 NoSymbol
- d72 1
- a72 1
- #define XK_R8 NoSymbol
- d74 7
- a80 7
- #define XK_L7 NoSymbol
- #define XK_L8 NoSymbol
- #define XK_R10 NoSymbol
- #define XK_R11 NoSymbol
- #define XK_R12 NoSymbol
- #define XK_L9 NoSymbol
- #define XK_L10 NoSymbol
- d82 1
- a82 1
- #define XK_R14 NoSymbol
- @
-
-
- 1.4
- log
- @adapted to Beta-0
- @
- text
- @d21 1
- a21 1
- "$Header: spriteKbd.c,v 1.3 87/06/17 17:18:20 deboor Exp $ SPRITE (Berkeley)";
- d52 32
- @
-
-
- 1.3
- log
- @Fixed problem with definition of VKEY_UP. the kernel gives
- back 0x80, not TRUE (ie. 1)
- @
- text
- @d21 1
- a21 1
- "$Header: spriteKbd.c,v 1.2 87/06/17 16:16:21 deboor Exp $ SPRITE (Berkeley)";
- d30 1
- a30 5
- typedef struct {
- int trans; /* Original translation form */
- int smask; /* State of shift modifiers */
- int ksmask; /* State of individual modifier keys */
- } SunKbPrivRec, *SunKbPrivPtr;
- a31 2
- #include "keynames.h"
-
- a41 1
- static SunKbPrivRec spriteKbPriv;
- d49 1
- a49 1
- (pointer)&spriteKbPriv, /* Private to keyboard device */
- a51 10
- /*
- * Constants for the ksmask field of the private data
- */
- #define SunLeftShiftMask (1<<0)
- #define SunRightShiftMask (1<<1)
- #define SunCtrlMask (1<<2)
- #define SunLeftMetaMask (1<<3)
- #define SunRightMetaMask (1<<4)
- #define SunCapsLockMask (1<<5)
- #define SunLockMask (1<<6)
- d54 129
- a182 13
- /*
- * The X window system expects key values to have the same values
- * as generated by the DEC LK201 keyboard. An array
- * is used to convert Sun raw key codes into the LK201 codes.
- *
- * Raw key codes that do not correspond to real keys are UNBOUND.
- *
- * Sun-{2,3} keyboard to LK201, shifted and unshifted.
- *
- * L1-L10 are the left function keys.
- * T1-T10 are the top function keys.
- * R1-R15 are the right function keys.
- */
- d184 4
- a187 5
- #define UNBOUND 0377
- #define KEY_LEFTSHIFT 99
- #define KEY_RIGHTSHIFT 110
- #define KEY_LEFTMETA 120
- #define KEY_RIGHTMETA 122
- d189 3
- a191 66
-
- static unsigned char sunToLK201Map[] = {
- /* 0 */ UNBOUND, UNBOUND, /* L1 */
- /* 2 */ UNBOUND, UNBOUND, /* L2 */
- /* 4 */ UNBOUND, KEY_F1, /* T1 */
- /* 6 */ KEY_F2, /* T2 */ UNBOUND,
- /* 8 */ KEY_F3, /* T3 */ UNBOUND,
- /* 10 */ KEY_F4, /* T4 */ UNBOUND,
- /* 12 */ KEY_F5, /* T5 */ UNBOUND,
- /* 14 */ KEY_F6, /* T6 */ UNBOUND,
- /* 16 */ KEY_F7, /* T7 */ KEY_F8, /* T8 */
- /* 18 */ KEY_F9, /* T9 */ KEY_F10, /* T10 */
- /* 20 */ UNBOUND, UNBOUND, /* R1 */
- /* 22 */ UNBOUND, /* R2 */ UNBOUND, /* R3 */
- /* 24 */ UNBOUND, UNBOUND, /* L3 */
- /* 26 */ UNBOUND, /* L4 */ UNBOUND,
- /* 28 */ UNBOUND, KEY_ESC, /* ESC*/
- /* 30 */ KEY_TR_1, /* 1 */ KEY_TR_2, /* 2 */
- /* 32 */ KEY_TR_3, /* 3 */ KEY_TR_4, /* 4 */
- /* 34 */ KEY_TR_5, /* 5 */ KEY_TR_6, /* 6 */
- /* 36 */ KEY_TR_7, /* 7 */ KEY_TR_8, /* 8 */
- /* 38 */ KEY_TR_9, /* 9 */ KEY_TR_0, /* 0 */
- /* 40 */ KEY_UBAR, /* - */ KEY_PLUS, /* = */
- /* 42 */ KEY_TILDE, /* ` */ KEY_BS, /* BS */
- /* 44 */ UNBOUND, UNBOUND, /* R4 */
- /* 46 */ UNBOUND, /* R5 */ UNBOUND, /* R6 */
- /* 48 */ UNBOUND, UNBOUND, /* L5 */
- /* 50 */ UNBOUND, UNBOUND, /* L6 */
- /* 52 */ UNBOUND, KEY_TAB, /* tab */
- /* 54 */ KEY_Q, /* q */ KEY_W, /* w */
- /* 56 */ KEY_E, /* e */ KEY_R, /* r */
- /* 58 */ KEY_T, /* t */ KEY_Y, /* y */
- /* 60 */ KEY_U, /* u */ KEY_I, /* i */
- /* 62 */ KEY_O, /* o */ KEY_P, /* p */
- /* 64 */ KEY_LBRACE, /* [ */ KEY_RBRACE, /* ] */
- /* 66 */ KEY_DELETE, /* del */ UNBOUND,
- /* 68 */ UNBOUND, KEY_UP, /* R8 */
- /* 70 */ UNBOUND, /* R9 */ UNBOUND,
- /* 72 */ UNBOUND, /* L7 */ UNBOUND, /* L8 */
- /* 74 */ UNBOUND, UNBOUND,
- /* 76 */ KEY_CTRL, /* ctl */ KEY_A, /* a */
- /* 78 */ KEY_S, /* s */ KEY_D, /* d */
- /* 80 */ KEY_F, /* f */ KEY_G, /* g */
- /* 82 */ KEY_H, /* h */ KEY_J, /* j */
- /* 84 */ KEY_K, /* k */ KEY_L, /* l */
- /* 86 */ KEY_SEMICOLON,/* ; */ KEY_QUOTE, /* ' */
- /* 88 */ KEY_VBAR, /* \ */ KEY_RETURN, /* ret */
- /* 90 */ UNBOUND, KEY_LEFT, /* R10 */
- /* 92 */ UNBOUND, /* R11 */ KEY_RIGHT, /* R12 */
- /* 94 */ UNBOUND, UNBOUND, /* L9 */
- /* 96 */ UNBOUND, KEY_LOCK, /* L10 */
- /* 98 */ UNBOUND, KEY_LEFTSHIFT,
- /* 100 */ KEY_Z, /* z */ KEY_X, /* x */
- /* 102 */ KEY_C, /* c */ KEY_V, /* v */
- /* 104 */ KEY_B, /* b */ KEY_N, /* n */
- /* 106 */ KEY_M, /* m */ KEY_COMMA, /* , */
- /* 108 */ KEY_PERIOD, /* . */ KEY_QMARK, /* / */
- /* 110 */ KEY_RIGHTSHIFT, KEY_LF, /* lf */
- /* 112 */ UNBOUND, /* R13 */ KEY_DOWN, /* R14 */
- /* 114 */ UNBOUND, /* R15 */ UNBOUND,
- /* 116 */ UNBOUND, UNBOUND,
- /* 118 */ UNBOUND, KEY_LOCK, /* caps*/
- /* 120 */ KEY_LEFTMETA, /* left */ KEY_SPACE, /* sp */
- /* 122 */ KEY_RIGHTMETA,/* right */ UNBOUND,
- /* 124 */ UNBOUND, UNBOUND,
- /* 126 */ UNBOUND, UNBOUND,
- a243 6
- spriteKbPriv.ksmask = spriteKbPriv.smask = 0;
-
- pKeyboard->deviceID = MakeDevice(DEVICE_KEYBOARD,
- SUN_SUN2,
- M_SUN,
- 0);
- a245 2
- spriteInitKbdMappings (map);
-
- d247 2
- a248 3
- InitKeyboardDeviceStruct(
- pKeyboard, map, MAP_LENGTH - 1, spriteBell,
- spriteKbdCtrl);
- a339 73
-
- /*-
- *-----------------------------------------------------------------------
- * spriteKbdPair --
- * Used for pairs of modifier keys which map to a single X keycode.
- * Make sure that the state of the single keycode reflects the
- * state of the two real keys. I.e. if one is down and the other
- * is pressed, don't send a KeyPressed event. etc.
- *
- * Results:
- * Returns TRUE if the event should be given to DIX and FALSE if it should
- * be discarded.
- *
- * Side Effects:
- * The smask and ksmask fields of the private data are altered.
- *
- *-----------------------------------------------------------------------
- */
- static Bool
- spriteKbdPair (pPriv, keyMask, pairMask, xKeyMask, state)
- SunKbPrivPtr pPriv; /* Private data for affected keyboard */
- int keyMask; /* Sun*Mask for key stroke */
- int pairMask; /* Sun*Mask for paired modifier key */
- int xKeyMask; /* Mask for equivalent X key */
- int state; /* State of the key in keyMask */
- {
- if (pPriv->smask & xKeyMask) {
- /*
- * Virtual key is already down. If this thing is the last of the
- * pair to go up, then the up event should be sent and we update
- * the smask to reflect the virtual key's new state.
- * If, however, this is the second of the pair to go down,
- * nothing should be sent and we merely record that the key
- * is down...
- */
- if (state == VKEY_UP) {
- pPriv->ksmask &= ~keyMask;
- if ((pPriv->ksmask & pairMask) == 0) {
- pPriv->smask &= ~xKeyMask;
- return TRUE;
- } else {
- return FALSE;
- }
- } else {
- pPriv->ksmask |= keyMask;
- if ((pPriv->ksmask & pairMask) == 0) {
- /*
- * This should never happen...
- */
- ErrorF("spriteKbdPair: xKey %x down but pair isn't\n", xKeyMask);
- }
- return FALSE;
- }
- } else {
- /*
- * If the virtual key is up, all this can really be is a down event
- * for one of the pair. We check just for debugging purposes.
- * For a down event, nothing special happens, the event is just
- * recorded in the private data.
- */
- if (state == VKEY_UP) {
- /*
- * This should never happen...
- */
- ErrorF("spriteKbdPair: xKey %x up when VKEY_UP received\n", xKeyMask);
- return FALSE;
- } else {
- pPriv->smask |= xKeyMask;
- pPriv->ksmask |= keyMask;
- return TRUE;
- }
- }
- }
- a370 1
- register SunKbPrivPtr pSunPriv;
- a374 1
- pSunPriv = (SunKbPrivPtr) pPriv->devPrivate;
- d380 2
- a381 1
- xE.type = (ev->keyUp ? KeyRelease : KeyPress);
- a382 31
- xE.detail = sunToLK201Map[ev->key];
- switch (xE.detail) {
- case KEY_LEFTMETA:
- if (!spriteKbdPair (pSunPriv, SunLeftMetaMask, SunRightMetaMask,
- Mod1Mask, ev->keyUp)) {
- return;
- }
- xE.detail = KEY_META;
- break;
- case KEY_RIGHTMETA:
- if (!spriteKbdPair (pSunPriv, SunRightMetaMask, SunLeftMetaMask,
- Mod1Mask, ev->keyUp)) {
- return;
- }
- xE.detail = KEY_META;
- break;
- case KEY_LEFTSHIFT: /* Left-hand "Shift" key */
- if (!spriteKbdPair (pSunPriv, SunLeftShiftMask, SunRightShiftMask,
- ShiftMask, ev->keyUp)) {
- return;
- }
- xE.detail = KEY_SHIFT;
- break;
- case KEY_RIGHTSHIFT: /* Right-hand "Shift" key */
- if (!spriteKbdPair (pSunPriv, SunRightShiftMask, SunLeftShiftMask,
- ShiftMask, ev->keyUp)) {
- return;
- }
- xE.detail = KEY_SHIFT;
- break;
- }
- d403 1
- a403 1
-
- d406 3
- a408 2
- * spriteInitKbdMappings
- * Initialize mappings. This is a bit wasteful...
- d411 1
- d414 1
- d418 3
- a420 2
- spriteInitKbdMappings(map)
- BYTE *map;
- d422 1
- a422 14
- int i;
-
- bzero (map, MAP_LENGTH);
- for (i = 0; i < sizeof(sunToLK201Map)/sizeof(sunToLK201Map[0]); i++) {
- if (sunToLK201Map[i] != UNBOUND) {
- map[sunToLK201Map[i]] = sunToLK201Map[i];
- }
- }
-
- map[1] = KEY_META;
- map[KEY_SHIFT] = KEY_SHIFT;
- map[KEY_LOCK] = KEY_LOCK;
- map[KEY_CTRL] = KEY_CTRL;
- /* More meta keys...? */
- @
-
-
- 1.2
- log
- @Dropped a line in the map during translation...
- @
- text
- @d21 1
- a21 1
- "$Header: spriteKbd.c,v 1.1 87/06/16 12:21:13 deboor Exp $ SPRITE (Berkeley)";
- d38 1
- a38 1
- #define VKEY_UP 1
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d21 1
- a21 1
- "$Header: spriteKbd.c,v 2.7 87/05/28 21:49:46 deboor Exp $ SPRITE (Berkeley)";
- d126 2
- a127 1
- /* 66 */ KEY_DELETE, /* del */ KEY_UP, /* R8 */
- @
-